<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category WxArticle.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/8/14  15:19
 * +--------------------------------------------------------+
 */

namespace App\Models;


use App\Services\CollectService;
use QL\QueryList;

class WxArticle extends BaseModel
{
    protected $table = "wx_article";

    static public function getWxArticle()
    {

        $wx_num = [
            // ['wechat'=> 'wesley_capital','name'=>'卫斯理观察'],
            ['wechat' => 'LiuBeiJiaoShou', 'name' => '刘备教授'],
            ['wechat' => 'nunudedashu', 'name' => '孥孥的大树'],
        ];

        foreach ($wx_num as $key => $val) {
            $url = 'https://weixin.sogou.com/weixin?type=1&s_from=input&query=' . $val['wechat'] . '&ie=utf8&_sug_=n&_sug_type_=';
            //采集规则
            $reg = [
                //采集文章标题
                'title'   => ['li:first-child  dl a', 'text'],
                'content' => ['li:first-child dl a', 'href'],
                'author'  => ['li:first-child .gzh-box2 .txt-box .tit', 'text'],
            ];

            $rang = '.news-list2';

            $data = CollectService::getInstance()->collect($url, $reg, $rang);

            $url = 'https://weixin.sogou.com' . $data[0]['content'];

            return $url;

            // $article = self::where('title',$data[0]['title'])->where('author',$data[0]['author'])->first();
            //
            // if(empty($article)){
            //     self::create($data[0]);
            // }


        }
    }

}
